<template>
  <div>
      <table border="1">
          <th>ID</th>
          <th>姓名</th>
          <tr v-for="data in datas" :key="data.id">
              <td>{{data.id}}</td>
              <td>{{data.name}}</td>
          </tr>
      </table>
      <input type="text" v-model="from.name">
      <button @click="add">添加</button>
  </div>
</template>

<script>
export default {
    name:'p7',
    data(){
        return{
            datas:[],
            from:{}
        }
        
    },methods: {
        getlist(){
            this.$axios.get('/add').then(res=>{
                this.datas=res.data.list

            })
        },
        add(){
            this.$axios.post('/add',this.from).then(res=>{
                this.datas=res.data.list
                alert('添加成功')
                this.getlist()
            })
        }
    },mounted(){
        this.getlist();
    }
    
}
</script>

<style>

</style>